package com.ruoyi.suggest.controller;

import java.util.List;

import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.suggest.domain.ChatSuggestQuestion;
import com.ruoyi.suggest.service.IChatSuggestQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 推荐问题Controller
 * @author wangz
 */
@Tag(name = "推荐问题管理")
@RestController
@RequestMapping("/system/suggest/question")
public class ChatSuggestQuestionController extends BaseController {
    @Autowired
    private IChatSuggestQuestionService chatSuggestQuestionService;

    @Operation(
            summary = "查询推荐问题列表",
            parameters = {
                    @Parameter(name = "chatSuggestQuestion", description = "推荐问题信息")
            }
    )
    @PreAuthorize("@ss.hasPermi('suggest:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatSuggestQuestion chatSuggestQuestion) {
        startPage();
        List<ChatSuggestQuestion> list = chatSuggestQuestionService.selectChatSuggestQuestionList(chatSuggestQuestion);
        return getDataTable(list);
    }

    @Operation(
            summary = "导出推荐问题列表",
            parameters = {
                    @Parameter(name = "chatSuggestQuestion", description = "推荐问题信息")
            })
    @PreAuthorize("@ss.hasPermi('suggest:question:export')")
    @Log(title = "推荐问题", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChatSuggestQuestion chatSuggestQuestion) {
        List<ChatSuggestQuestion> list = chatSuggestQuestionService.selectChatSuggestQuestionList(chatSuggestQuestion);
        ExcelUtil<ChatSuggestQuestion> util = new ExcelUtil<ChatSuggestQuestion>(ChatSuggestQuestion.class);
        return util.exportExcel(list, "question");
    }

    @Operation(
            summary = "获取推荐问题详情",
            parameters = {
                    @Parameter(name = "id", description = "推荐问题ID")
            })
    @PreAuthorize("@ss.hasPermi('suggest:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(chatSuggestQuestionService.selectChatSuggestQuestionById(id));
    }

    @Operation(
            summary = "新增推荐问题",
            parameters = {
                    @Parameter(name = "chatSuggestQuestion", description = "推荐问题信息")
            })
    @PreAuthorize("@ss.hasPermi('suggest:question:add')")
    @Log(title = "推荐问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatSuggestQuestion chatSuggestQuestion) {
        return toAjax(chatSuggestQuestionService.insertChatSuggestQuestion(chatSuggestQuestion));
    }

    @Operation(
            summary = "修改推荐问题",
            parameters = {
                    @Parameter(name = "chatSuggestQuestion", description = "推荐问题信息")
            })
    @PreAuthorize("@ss.hasPermi('suggest:question:edit')")
    @Log(title = "推荐问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatSuggestQuestion chatSuggestQuestion) {
        return toAjax(chatSuggestQuestionService.updateChatSuggestQuestion(chatSuggestQuestion));
    }

    @Operation(
            summary = "删除推荐问题",
            parameters = {
                    @Parameter(name = "ids", description = "推荐问题ID")
            })
    @PreAuthorize("@ss.hasPermi('suggest:question:remove')")
    @Log(title = "推荐问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(chatSuggestQuestionService.deleteChatSuggestQuestionByIds(ids));
    }

    @Operation(
            summary = "获取所有启用的推荐问题")
    @GetMapping("/api/enabled")
    public AjaxResult getEnabledQuestions() {
        List<ChatSuggestQuestion> list = chatSuggestQuestionService.selectEnabledChatSuggestQuestions();
        return AjaxResult.success(list);
    }
}
